<template>
    <div class="district-energy-progress">
        <div class="progress-list">
            <div class="list-header">
                <div class="district-name">区域名称</div>
                <div class="energy-value">总排放(tCO2e)</div>
            </div>
            <div
                v-for="(item, index) in energyData"
                :key="index"
                class="progress-item"
            >
                <div class="item-header">
                    <div class="district-name">{{ item.district }}</div>
                    <div class="energy-value">{{ item.energy.toLocaleString() }}</div>
                </div>
                <div class="progress-wrapper">
                    <el-progress
                        :percentage="getPercentage(item.energy)"
                        :stroke-width="8"
                        :show-text="false"
                        :color="progressColor"
                        class="energy-progress"
                    />
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'DistrictEnergyProgress',
    data() {
        return {
            energyData: [
                {district: 'A区', energy: 135666},
                {district: 'B区', energy: 121034},
                {district: 'C区', energy: 101023},
                {district: 'D区', energy: 76098},
                {district: 'E区', energy: 23293},
                {district: 'F区', energy: 135666}
            ],
            progressColor: '#ff6b47'
        }
    },
    computed: {
        maxEnergy() {
            return Math.max(...this.energyData.map(item => item.energy))
        }
    },
    methods: {
        getPercentage(energy) {
            return Math.round((energy / this.maxEnergy) * 100)
        },
        updateData(newData) {
            this.energyData = newData
        }
    }
}
</script>

<style lang="scss" scoped>
.district-energy-progress {
    width: 100%;
    background: #fff;
    padding: 16px 24px 0 24px;
}

.progress-list {
    display: flex;
    flex-direction: column;
    gap: 8px;

    .list-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #1F2D35;
    }
}

.progress-item {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    gap: 8px;

    .item-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 4px;
    }

    .district-name {
        font-size: 16px;
        font-weight: 500;
    }

    .energy-value {
        font-size: 16px;
        font-weight: 500;
    }

    .progress-wrapper {
        width: 100%;
    }

    .energy-progress {
        margin: 0;
    }
}

.progress-item:nth-child(-n+4){
    .district-name {
        color: #ff6b47;
    }

    .energy-value {
        color: #ff6b47;
    }
}

/* 自定义进度条样式 */
::v-deep .el-progress {
    display: flex;
    align-items: center;
}

::v-deep .el-progress-bar {
    flex: 1;
    padding-right: 0;
}

::v-deep .el-progress-bar__outer {
    background-color: #e8e8e8;
    border-radius: 10px;
    overflow: hidden;
}

::v-deep .el-progress-bar__inner {
    background: linear-gradient(90deg, #ff8a65 0%, #ff6b47 100%);
    border-radius: 10px;
    transition: width 0.6s ease;
}

/* 悬停效果 */
.progress-item:hover {
    background-color: #fafafa;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.progress-item:hover .district-name,
.progress-item:hover .energy-value {
    color: #ff5722;
}

/* 动画效果 */
.progress-item {
    opacity: 0;
    transform: translateY(20px);
    animation: slideUp 0.6s ease forwards;
}

.progress-item:nth-child(1) {
    animation-delay: 0.1s;
}

.progress-item:nth-child(2) {
    animation-delay: 0.2s;
}

.progress-item:nth-child(3) {
    animation-delay: 0.3s;
}

.progress-item:nth-child(4) {
    animation-delay: 0.4s;
}

.progress-item:nth-child(5) {
    animation-delay: 0.5s;
}

.progress-item:nth-child(6) {
    animation-delay: 0.6s;
}

@keyframes slideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
</style>
